package com.project.dao.impl;


import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

/**
 * DAO的父类
 */
public class BaseDao {
    /**连接*/
    protected Connection con;
    /**SQL语句执行对象*/
    protected PreparedStatement ps;
    /**结果集*/
    protected ResultSet rs;

    public void setConnection(){
        try {
            Class.forName("com.mysql.jdbc.Driver");
                    con= DriverManager.getConnection("jdbc:mysql://localhost:12345/db?characterEncoding=utf-8","root","lovo");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void closeConnection(){
        try {
            if(rs != null) {
                rs.close();
            }
            if(ps != null) {
                ps.close();
            }
            if(con != null) {
                con.close();
            }

        } catch (Exception throwables) {
            throwables.printStackTrace();
        }
    }
//    /**
//     * 添加
//     * @return
//     */
//    public ProductBean getUser(ResultSet res){
//        ProductBean order = new ProductBean();
//        try {
//            order.setName(res.getString("p_name"));
//            order.setId(res.getInt("pk_productsId"));
//            order.setPrice(res.getInt("p_price"));
//            String bir = res.getString("p_createDate");
//            order.setCreateDate(bir!=null? LocalDate.parse(bir):null);
//        } catch (SQLException e) {
//            e.printStackTrace();
//        }
//        return order;
//    }
}
